package com.gexin.common.job;

import com.gexin.model.activity.MemberInfo;
import com.gexin.model.enums.MemberInfoEnum;
import com.gexin.model.order.OrderItem;
import com.gexin.service.memberAcitivty.InviterService;
import com.jfinal.log.Log;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.impl.JobDetailImpl;
import org.quartz.impl.triggers.CronTriggerImpl;

import java.util.List;

/**
 * 活动任务定时器
 */

public class ActivityJob implements Runnable {

    static Log log = Log.getLog(OrderJob.class);


    @Override
    public void run() {
        InviterService inviterService = new InviterService();
        inviterService.groupByPoint();
    }


    //        List<MemberInfo> memberInfos = null;
//        memberInfos = (List<MemberInfo>) MemberInfo.dao.find("select * from t_memeber_info where level=1");
//        OrderItem orderItem = new OrderItem();
//        OrderItem.dao.findOrderItemByOrderId("");
//        memberInfos.forEach(memberInfo -> {
//            if(memberInfo){
//
//            }
//            memberInfo.setIntegral(0);
//            memberInfo.update();
//        });
//    }

//    private static String JOB_GROUP_NAME = "EXTJWEB_JOBGROUP_NAME";
//    private static String TRIGGER_GROUP_NAME = "EXTJWEB_TRIGGERGROUP_NAME";

    /**
     * @param sched            调度器
     * @param jobName          任务名
     * @param jobGroupName     任务组名
     * @param triggerName      触发器名
     * @param triggerGroupName 触发器组名
     * @param jobClass         任务
     * @param time             时间设置，参考quartz说明文档
     * @Description: 添加一个定时任务
     * @Title: QuartzManager.java
     */
    public static void addJob(Scheduler sched, String jobName, String jobGroupName, String triggerName, String triggerGroupName, @SuppressWarnings("rawtypes") Class jobClass, String time) {
        try {
            JobDetail jobDetail = new JobDetailImpl(jobName, jobGroupName, jobClass);// 任务名，任务组，任务执行类
            // 触发器
            CronTriggerImpl trigger = new CronTriggerImpl(triggerName, triggerGroupName);// 触发器名,触发器组
            trigger.setCronExpression(time);// 触发器时间设定
            sched.scheduleJob(jobDetail, trigger);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}